

class Student {
    private String name = "yxj";
    public int age = 19;

    public Student() {
        System.out.println("Student()");
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Student(String,name)");
    }

    private void eat() {
        System.out.println("i am eat");
    }

    private void sleep() {
        System.out.println("you are a pig");
    }

    private void function(String str) {
        System.out.println(str);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static class Test {
        public static void main(String[] args) throws ClassNotFoundException {
            //Class对象只有一个
            //获取Class类
            Student student = new Student();
            //1.
            Class<?> c1 = student.getClass();

            //2.
            Class<?> c2 = Student.class;

            //3.括号里面写的是当前类的路径
            Class<?> c3 = Class.forName("Student");//受查异常，编译时异常
            //Class.forName("demo.Student");//如果是在某个包下面就这样写

            System.out.println(c1 == c2);
            System.out.println(c1 == c3);
            System.out.println(c2 == c3);
        }
    }

}


